import psutil
import torch

def print_resource_usage(rank):
    if torch.cuda.is_available():
        alloc = torch.cuda.memory_allocated()/1024**2
        cached = torch.cuda.memory_reserved()/1024**2
        print(f"[Rank {rank}] GPU Mem - Alloc: {alloc:.2f}MB, Cached: {cached:.2f}MB")
    print(f"[Rank {rank}] CPU Usage: {psutil.cpu_percent()}%")